<?php
/* $Id: reports.php,v 1.5 2003/10/08 07:24:55 tuxmonkey Exp $ */

if (strpos($_SERVER['PHP_SELF'],basename(__FILE__)) !== false) {
  print "Direct module access forbidden.".basename(__FILE__);exit;}
  
$rep = new ITreport;

$fields = array(
  "assigned_to" => $lg->assigned_to,
  "opened_by"   => $lg->opened_by,
  "opened"      => $rep->time_opened,
  "closed"      => $rep->time_closed,
  "modified"    => $lg->last_modified,
//  "status"      => $lg->status,
  "category"    => $lg->type,
  "product"     => $lg->product,
  "severity"    => $rep->show_priority,
  "problem"     => $lg->long_description,
);

$options = array(
  "avgclose"    => $rep->avgclose,
  "maxclose"    => $rep->maxclose,
  "avgfirst"    => $rep->avgfirst,
  "maxfirst"    => $rep->maxfirst,
  "percat"      => $rep->percat,
  "perstat"     => $rep->perstat,
  "perprod"     => $rep->perprod,
  "persev"      => $rep->persev,
  "pertech"     => $rep->pertech,
  "opened"      => $rep->nb_opened,
  "resolved"    => $rep->resolved,
  "numevents"   => $rep->numevents
);
  
if (is_employee()) {
  $options['escto'] = "Issues Escalated To Group";
  $options['escfrom'] = "Issues Escalated From Group";
  $options['numhours'] = "Number of Hours Logged";
  
  if (is_manager()) {
    $sql  = "SELECT gid ";
    $sql .= "FROM groups ";
    $sql .= "ORDER BY name";
    $groups = $dbi->fetch_all($sql);
    $smarty->assign('groups',$groups);
  } else {
    $smarty->assign('groups',$_SESSION['groups']);
  }

  $template = "reports/employee.tpl";
} else {
  if (empty($_POST['gid']) and $_SESSION['group_count'] == 1) {
    $_POST['gid'] = $_SESSION['groups'][0];
  }

  $template = "reports/client.tpl";
}

$saved = array();
$sql  = "SELECT rid,name ";
$sql .= "FROM reports ";
$sql .= "WHERE userid='".$_SESSION['userid']."' ";
$sql .= "ORDER BY name";
$reports = $dbi->fetch_all($sql,"array");
if (is_array($reports)) {
  foreach ($reports as $report) {
    $saved[$report['rid']] = $report['name'];
  }
}
$smarty->assign('saved',$saved);
$smarty->assign('options',$options);
$smarty->assign('fields',$fields);
$smarty->display($template);
?>